﻿using System.Web.Mvc;
using Kratos.Framework.Filters;
using Kratos.Framework.Modules.Core.Controllers;
using Kratos.Framework.Modules.Core.Services;

namespace Kratos.Modules.Admin.Controllers
{
    public class HomeController : KratosController
    {
        private readonly IMenuPermissionService _menuSrv;

        public HomeController(IMenuPermissionService menuSrv)
        {
            _menuSrv = menuSrv;
        }

        public ActionResult Index()
        {
            return View();
        }

        [Ajax]
        public ActionResult GetMenuByParentId(int? parentId)
        {
            if (parentId == null || parentId == -1)
            {
                var model = _menuSrv.GetMenusByLevel(1);

                return KratosJson(model);
            }
            else
            {
                var model = _menuSrv.GetMenu(parentId.Value);

                return KratosJson(model);
            }
        }
    }
}
